/**
 * Copyright (c) 2021 765819328@qq.com
 * All rights reserved.
 * Created on 2021-09-27
 */
package com.chiang.springcloud.controller;

import com.chiang.springcloud.entities.CommonResult;
import com.chiang.springcloud.entities.Payment;
import com.chiang.springcloud.enu.ReturnCode;
import com.chiang.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : 765819328@qq.com
 * @version :
 * @date : Created in 2021/9/27 16:12
 * @description: 支付服务
 * @modified By:
 */
@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/create")
    public CommonResult creatPayment(@RequestBody Payment payment) {
        int result = paymentService.create(payment);
        log.info("result:" + result);
        if (result > 0) {
            return new CommonResult(ReturnCode.SUCCESS.code(), ReturnCode.SUCCESS.message(), result);
        } else {
            return new CommonResult(ReturnCode.ERROR.code(), ReturnCode.ERROR.message(), result);
        }
    }

    @GetMapping(value = "/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        log.info("result:" + payment);
        if (ObjectUtils.isEmpty(payment)) {
            return new CommonResult(ReturnCode.ERROR.code(), ReturnCode.ERROR.message());
        } else {
            return new CommonResult(ReturnCode.SUCCESS.code(), ReturnCode.SUCCESS.message(), payment);
        }
    }

}
